<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>race</title>
</head>

<body>
    <script>
        Promise._race = function(promises){
            return new Promise((resolve, reject) => {
                promises.forEach(promise => {
                    //then回调时会根据异步执行状态，调用resolve/reject中的一个，并将异步结果作为参数传入，如 resolve(result)
                    //因此正好完成了对 返回的promise的状态确定 并传递了参数
                    promise.then(resolve, reject)
                });
            })
        }

        const promise1 = new Promise((resolve, reject) => {
            setTimeout(resolve, 500, 'one');
        });

        const promise2 = new Promise((resolve, reject) => {
            setTimeout(resolve, 100, 'two');
        });

        Promise._race([promise1, promise2]).then((value) => {
            console.log(value);
        });
    </script>
</body>

</html>